/**
 * Created by hubery on 2017/8/8.
 */
import Axios from 'axios';
import store from '../store/index'
export default function baseRequest(parameter, requestConfig) {
  // let url = (requestConfig.api || "/api") + requestConfig.url;
  let url = 'https://enrestfulapi.iccsino.com/' + requestConfig.url;
  let tokenid = store.state.loginInforXl.tokenid;
  return new Promise((resolve, reject) => {
    var paramsobj = {
      url: url,
      method: requestConfig.method || 'post',
      headers: requestConfig.headers || {
        'content-type': 'application/json',
        'icc': "iccapp"  ,
        'tokenid':tokenid
      },
      data: parameter
    }
    // console.log(paramsobj)
    Axios(paramsobj).then((res) => {
      if (res.status === 200) {
        const responseData = res.data;
 
        if (responseData.code == '0000') {
          resolve(responseData);
  
        } else {
          resolve(responseData);
          store.dispatch('acrefresh',true)
        }
      } else {
        // http请求无响应
        reject('网络异常，请检查网络后重试!');
      }
    }, (err) => {
      reject(err);
    });
  });
}
